#!/usr/bin/env python3
# encoding: utf-8

"""
@version: 1.0
@author: 周永波
@file: hello.py
@time: 2020/7/18 10:13
"""
import json

import numpy as np
from django.http import JsonResponse, HttpResponse
from django.shortcuts import render
from data.models import Student
from result.RetException import RetException


def hello(request):
    return JsonResponse({"success": True, "messages": '日狗了'}, json_dumps_params={'ensure_ascii': False})


def test(request):
    return HttpResponse(json.dumps({"success": True, "messages": "测试"}, ensure_ascii=False))


def test1(request):
    return "test1"

def exception(request):
    if True:
        raise RetException("测试错误","102")
    return ""

def temTest(request):
    student = Student(name="abc", age=13)
    student.save()
    # Student.objects.filter(id__in=[1, 2, 3]).delete()
    Student.objects.filter(name__in=['abc']).delete()
    student.save()
    sl = Student.objects.all().filter(name='abc')
    # Student.objects.filter(name='abc')
    # Student.objects.in_bulk(id_list=[1, 2, 3], field_name="id").delete()

    a = [2, 4, 6, 8, 10]
    average_a = np.mean(a)
    print(average_a)
    return render(request, "index.html", {"sl": sl})